﻿/**
 * GoText Palm: A program that allows to send text messages over the internet.
 *  Copyright (C) 2008 Nicola 'Gawaine' Racco
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace GoTextPalm.Core.Localization.Reducer
{
    public class Italian : IRedCmd, IConvCmd
    {
        public String Reduce(ReduceLevel level, String text)
        {
            if (level >= ReduceLevel.L1)
                text = level1(text);
            if (level >= ReduceLevel.L2)
                text = level2(text);
            if (level >= ReduceLevel.L3)
                text = level3(text);
            if (level >= ReduceLevel.L4)
                text = level4(text);
            return text;
        }

        public String Convert(String text)
        {
            StringBuilder sb = new StringBuilder(text);
            sb.Replace("À", "A'");
            sb.Replace("Á", "A'");
            sb.Replace("à", "a'");
            sb.Replace("á", "a'");
            sb.Replace("È", "E'");
            sb.Replace("É", "E'");
            sb.Replace("è", "e'");
            sb.Replace("é", "e'");
            sb.Replace("Ì", "I'");
            sb.Replace("Í", "I'");
            sb.Replace("ì", "i'");
            sb.Replace("í", "i'");
            sb.Replace("Ò", "O'");
            sb.Replace("Ó", "O'");
            sb.Replace("ò", "o'");
            sb.Replace("ó", "o'");
            sb.Replace("Ù", "U'");
            sb.Replace("Ú", "U'");
            sb.Replace("ù", "u'");
            sb.Replace("ú", "u'");
            return sb.ToString();
        }

        private String level1(String text)
        {
            StringBuilder sb = new StringBuilder(text);
            sb.Replace("piu'", "+");
            sb.Replace("PIU'", "+");
            sb.Replace("Piu'", "+");
            sb.Replace("meno", "-");
            sb.Replace("MENO", "-");
            sb.Replace("Meno", "-");
            sb.Replace("per", "x");
            sb.Replace("PER", "X");
            sb.Replace("Per", "X");
            sb.Replace("uno", "1");
            sb.Replace("UNO", "1");
            sb.Replace("Uno", "1");
            sb.Replace("una ", "1");
            sb.Replace("UNA ", "1");
            sb.Replace("Una ", "1");
            sb.Replace("un ", "1");
            sb.Replace("UN ", "1");
            sb.Replace("Un ", "1");
            sb.Replace("sei", "6");
            sb.Replace("SEI", "6");
            sb.Replace("Sei", "6");
            sb.Replace("  ", " ");
            sb.Replace("...", "..");
            sb.Replace("....", "..");
            sb.Replace(", ", ",");
            sb.Replace(". ", ".");
            sb.Replace("; ", ";");
            sb.Replace(": ", ":");
            sb.Replace("! ", "!");
            sb.Replace("? ", "?");
            sb.Replace("+ ", "+");
            sb.Replace(" +", "+");
            sb.Replace("- ", "-");
            sb.Replace(" -", "-");
            sb.Replace("X ", "X");
            sb.Replace(" X", "X");
            sb.Replace("1 ", "1");
            sb.Replace(" 1", "1");
            sb.Replace("6 ", "6");
            sb.Replace(" 6", "6");
            return sb.ToString();
        }

        private String level2(String text)
        {
            StringBuilder sb = new StringBuilder(text);
            sb.Replace("ch", "k");
            sb.Replace("CH", "K");
            sb.Replace("Ch", "K");
            sb.Replace("comunque", "cmq");
            sb.Replace("COMUNQUE", "CMQ");
            sb.Replace("Comunque", "Cmq");
            sb.Replace("non", "nn");
            sb.Replace("NON", "NN");
            sb.Replace("Non", "Nn");
            sb.Replace("dove", "dv");
            sb.Replace("DOVE", "DV");
            sb.Replace("Dove", "Dv");
            sb.Replace("questo", "qst");
            sb.Replace("QUESTO", "QST");
            sb.Replace("Questo", "Qst");
            sb.Replace("questa", "qst");
            sb.Replace("QUESTA", "QST");
            sb.Replace("Questa", "Qst");
            sb.Replace("quest", "qst");
            sb.Replace("QUEST", "QST");
            sb.Replace("Quest", "Qst");
            sb.Replace("quello", "ql");
            sb.Replace("QUELLO", "QL");
            sb.Replace("Quello", "Ql");
            sb.Replace("quella", "ql");
            sb.Replace("QUELLA", "QL");
            sb.Replace("Quella", "Ql");
            sb.Replace("quel", "ql");
            sb.Replace("QUEL", "QL");
            sb.Replace("Quel", "Ql");
            sb.Replace("quando", "qnd");
            sb.Replace("QUANDO", "QND");
            sb.Replace("Quando", "Qnd");
            sb.Replace("due", "2");
            sb.Replace("DUE", "2");
            sb.Replace("Due", "2");
            sb.Replace("tre", "3");
            sb.Replace("TRE", "3");
            sb.Replace("Tre", "3");
            sb.Replace("quattro", "4");
            sb.Replace("QUATTRO", "4");
            sb.Replace("Quattro", "4");
            sb.Replace("cinque", "5");
            sb.Replace("CINQUE", "5");
            sb.Replace("Cinque", "5");
            sb.Replace("sette", "7");
            sb.Replace("SETTE", "7");
            sb.Replace("Sette", "7");
            sb.Replace("otto", "8");
            sb.Replace("OTTO", "8");
            sb.Replace("Otto", "8");
            sb.Replace("nove", "9");
            sb.Replace("NOVE", "9");
            sb.Replace("Nove", "9");
            sb.Replace("zero", "0");
            sb.Replace("ZERO", "0");
            sb.Replace("Zero", "0");
            return sb.ToString();
        }

        private String level3(String text)
        {
            StringBuilder sb = new StringBuilder(text);
            String[] words = sb.ToString().Split(' ');
            sb.Remove(0, sb.Length);
            foreach (String s in words)
                if (s.Length > 1)
                    sb.Append(Char.ToUpper(s[0]) + s.Substring(1).ToLower());
                else
                    sb.Append(Char.ToUpper(s[0]));
            return sb.ToString();
        }

        private String level4(String text)
        {
            StringBuilder sb = new StringBuilder(text);
            sb.Replace("bi", "b");
            sb.Replace("Bi", "B");
            sb.Replace("ci", "c");
            sb.Replace("Ci", "C");
            sb.Replace("di", "d");
            sb.Replace("Di", "D");
            sb.Replace("gi", "g");
            sb.Replace("Gi", "G");
            sb.Replace("pi", "p");
            sb.Replace("Pi", "P");
            sb.Replace("qu", "q");
            sb.Replace("Qu", "Q");
            sb.Replace("ti", "t");
            sb.Replace("Ti", "T");
            sb.Replace("vi", "v");
            sb.Replace("Vi", "V");
            sb.Replace("effe", "f");
            sb.Replace("Effe", "F");
            sb.Replace("acca", "h");
            sb.Replace("Acca", "H");
            sb.Replace("elle", "l");
            sb.Replace("Elle", "L");
            sb.Replace("emme", "m");
            sb.Replace("Emme", "M");
            sb.Replace("enne", "n");
            sb.Replace("Enne", "N");
            sb.Replace("erre", "r");
            sb.Replace("Erre", "R");
            sb.Replace("esse", "s");
            sb.Replace("zeta", "z");
            sb.Replace("Zeta", "Z");
            return sb.ToString();
        }
    }
}
